package com.qf.service.impl;

import com.qf.dao.UserDao;
import com.qf.dao.impl.UserDaoImpl;
import com.qf.model.User;
import com.qf.model.UserCard;
import com.qf.service.UserService;

import java.math.BigDecimal;
import java.util.List;

public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();
    @Override
    public int regist(User user) {
        return userDao.regist(user);
    }

    @Override
    public User findUser(String phone) {
        return userDao.findUser(phone);
    }

    @Override
    public int update(User user1) {
        return userDao.update(user1);
    }

    @Override
    public int setPayPassword(String payPassword,int uid,String cid) {
        return userDao.setPayPassword(payPassword,uid,cid);
    }

    @Override
    public UserCard findOnCard(String cardnum,String onCardPassword) {
        return userDao.findOnCard(cardnum,onCardPassword);
    }

    @Override
    public int addUserCard(UserCard onCard) {
        return userDao.addUserCard(onCard);
    }

    @Override
    public User select(User user) {
        return userDao.select(user);
    }

    @Override
    public int updateUserMsg(User user) {
        return userDao.updateUserMsg(user);
    }

    //查询用户银行卡列表
    @Override
    public List<UserCard> findAllCard(User user1) {
        return userDao.findAllCard(user1);
    }

    //查询所有卡余额
    @Override
    public BigDecimal findAllCardMoney(List<UserCard> usercads) {
        BigDecimal allCardMoney = new BigDecimal(0);
        for (UserCard userCard:usercads) {
           allCardMoney = allCardMoney.add(userCard.getMoney());
        }
        return allCardMoney;
    }

    @Override
    public User login(User user) {
        return userDao.login(user);
    }
}
